package com.sunlands.zlcx.usercenter.repository;

import com.sunlands.zlcx.usercenter.domain.UsersLearnNameHistoryDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;


@Repository
public interface LearnNameHistoryRepository extends JpaRepository<UsersLearnNameHistoryDO, Long>, JpaSpecificationExecutor<UsersLearnNameHistoryDO> {

    @Query(value = "select * from tz_learn_name_history where user_id = ?1 order by create_time desc limit 0,1", nativeQuery = true)
    UsersLearnNameHistoryDO findByUserIdOne(Long userId);

    List<UsersLearnNameHistoryDO> findByUserIdAndStatusInAndCreateTimeAfter(Long userId, List<Integer> status, Date createTime);

    List<UsersLearnNameHistoryDO> findByUserIdAndCreateTimeAfter(Long userId, Date createTime);

    List<UsersLearnNameHistoryDO> findByUserIdAndStatus(Long userId, Integer status);

    List<UsersLearnNameHistoryDO> findByUserId(Long userId);

    UsersLearnNameHistoryDO findFirstByUserIdAndLearnName(Long userId, String studyName);
}

